using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Protocol;
using MicroMsg.Scene;
using System;
using System.Collections.Generic;
namespace MicroMsg.Plugin.DriftBottle.Scene
{
	public class NetSceneGetBottleCount : NetSceneBaseEx<GetBottleCountRequest, GetBottleCountResponse, GetBottleCountRequest.Builder>
	{
		private const string TAG = "NetSceneGetBottleCount";
		public bool doScene()
		{
			return new NetSceneGetBottleCount().doSceneEx();
		}
		private bool doSceneEx()
		{
			base.beginBuilder();
			this.mBuilder.UserName = AccountMgr.curUserName;
			this.mBuilder.RequestTime = (uint)Util.getNowSeconds();
			this.mSessionPack.mCmdUri = "/cgi-bin/micromsg-bin/getbottlecount";
			this.mSessionPack.mConnectMode = 2;
			base.endBuilder();
			return true;
		}
		protected override void onFailed(GetBottleCountRequest request, GetBottleCountResponse response)
		{
			Log.smethod_1("NetSceneGetBottleCount", "Get Bottle Count failed system error!");
			EventCenter.postEvent(EventConst.ON_NETSCENE_GRIFTBOTTLE_EVENT, new BottleCountRet(BottleEvent.ON_NETSCENE_GETBOTTLECOUNT_FAIL, 0, 0), null);
		}
		protected override void onSuccess(GetBottleCountRequest request, GetBottleCountResponse response)
		{
			if (response != null && response.Ret == 0)
			{
				Log.smethod_5("NetSceneGetBottleCount", "onSuccess response.ThrowCount = " + response.ThrowCount);
				Log.smethod_5("NetSceneGetBottleCount", "onSuccess response.PickCount = " + response.PickCount);
				BottleCountRet bottleCountRet = new BottleCountRet(BottleEvent.ON_NETSCENE_GETBOTTLECOUNT_SUCCESS, response.ThrowCount, response.PickCount);
				if (response.WordListCount > 0)
				{
					bottleCountRet.wordList = new List<string>();
					using (IEnumerator<SKBuiltinString_t> enumerator = response.WordListList.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							SKBuiltinString_t current = enumerator.get_Current();
							string text = current.ToString();
							bottleCountRet.wordList.Add(text);
						}
					}
				}
				EventCenter.postEvent(EventConst.ON_NETSCENE_GRIFTBOTTLE_EVENT, bottleCountRet, null);
				return;
			}
			Log.smethod_1("NetSceneGetBottleCount", "Ge tBottle Count Ret is not OK Ret = " + ((RetConst)response.Ret).ToString());
			EventCenter.postEvent(EventConst.ON_NETSCENE_GRIFTBOTTLE_EVENT, new BottleCountRet(BottleEvent.ON_NETSCENE_GETBOTTLECOUNT_FAIL, 0, 0), null);
		}
	}
}
